package com.hfdg.coordination.ctrl;

import com.hfdg.prototype.base.model.AjaxResult;
import com.hfdg.coordination.entity.CoordTask;
import com.hfdg.coordination.service.CoordTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.Model;

/**
 * @ClassName CoordTaskCtrl
 * @Description TODO
 * @Company 会飞的锅工作室
 * @Author yuelh
 * @Email 18695867679@163.com
 * @Date 2020/05/18 07:02:30
 * @Version 1.0
 **/
@Controller
@RequestMapping("/coordTask")
public class CoordTaskCtrl {
    @Autowired
    CoordTaskService coordTaskService;
     /**
     * @Author: yuelh
     * @Description:  TODO 保存数据
     * @Date:  2020/05/18 19:02:30
     * @Param: coordTask
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save (CoordTask coordTask){
        if(null!=coordTask.getUid()&&!"".equals(coordTask.getUid().trim())){
            coordTaskService.update(coordTask);
        }else{
           coordTaskService.insert(coordTask);
        }
        return AjaxResult.success();
    }
     /**
     * @Author: yuelh
     * @Description:  TODO 根据UID删除数据
     * @Date:  2020/05/18 19:02:30
     * @Param: uid 要删除的数据条目的uid
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String uid){
            coordTaskService.delete(uid);
            return AjaxResult.success();
    }
    /**
         * @Author: yuelh
         * @Description:  TODO 根据UID删除数据
         * @Date:  2020/05/18 19:02:30
         * @Param: uid 要删除的数据条目的uid
         * @return: com.hfdg.base.domains.AjaxResult
         **/
        @RequestMapping("/batchRemove")
        @ResponseBody
        public AjaxResult batchRemove(@RequestParam("uids[]") String[] uids){
                 coordTaskService.batchDelete(uids);
                return AjaxResult.success();
        }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表
     * @Date:  2020/05/18 19:02:30
     * @Param: coordTask 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/list")
    @ResponseBody
    public  AjaxResult list(CoordTask coordTask){
        return AjaxResult.success(coordTaskService.list(coordTask));
    }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表,分页
     * @Date:  2020/05/18 19:02:30
     * @Param: offset 数据偏移值，limit 单页最大记录数，orderBy 排序字段 ，coordTask 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/getPagingData")
    @ResponseBody
    public AjaxResult getPagingData(Integer offset,Integer limit,String orderBy,CoordTask coordTask){
        return  AjaxResult.success(coordTaskService.getPagingData(offset,limit,orderBy,coordTask));
    }

     /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至表单页面
     * @Date:  2020/05/18 19:02:30
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toCreateView")
    public String toForm(HttpServletRequest request, HttpServletResponse response,Model model,String itemTitle,String itemUid){
        model.addAttribute("itemUid",itemUid);
        model.addAttribute("itemTitle",itemTitle);
        return "commons/"+"coordination"+"/"+"coordTaskCreateView";
    }

/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至编辑页面
     * @Date:  2020/05/18 19:02:30
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toEditView")
    public String toEditView(HttpServletRequest request, HttpServletResponse response,String uid,Model model){
            CoordTask coordTask= coordTaskService.get(uid);
            model.addAttribute("formData",coordTask);
            return "commons/"+"coordination"+"/"+"coordTaskEditView";
        }


/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至对应列表页面
     * @Date:  2020/05/18 19:02:30
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toListView")
    public String toListView(HttpServletRequest request, HttpServletResponse response){
        return "commons/"+"coordination"+"/"+"coordTaskListView";
    }

    /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转
     * @Date:  2020/05/18 19:02:30
     * @Param: page  要跳转的页面
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/view/{page}")
    public String view(HttpServletRequest request, HttpServletResponse response, @PathVariable("page") String page){
        return "commons/"+"coordination"+"/"+page;
    }
    @RequestMapping("/toTaskToDoListView")
    public String toTaskToDoListView(String assigneeUid){
        return "/commons/coordination/taskToDoListView";
    }

    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表,分页
     * @Date:  2020/05/18 19:02:30
     * @Param: offset 数据偏移值，limit 单页最大记录数，orderBy 排序字段 ，coordTask 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/getTaskToDoPagingData")
    @ResponseBody
    public AjaxResult getTaskToDoPagingData(Integer offset,Integer limit,String orderBy,CoordTask coordTask){
        return  AjaxResult.success(coordTaskService.getTaskToDoPagingData(offset,limit,orderBy,coordTask));
    }
    @RequestMapping("/toTaskDetailView")
    public String toTaskDetailView(String uid,Model model){
        CoordTask coordTask= coordTaskService.get(uid);
        model.addAttribute("formData",coordTask);
        model.addAttribute("description",coordTask.getDescription());
        return "commons/"+"coordination"+"/taskDetailView";
    }


}
